/-app
FileTree.ts
TopLayout.ts
main.css
start.ts
/-files ...
FileTree.ts
SyncStorageAccess.ts
/-imports
/-storage
/-typings
functions.ts
index.html
try.js
x
​
 
1
module teapo.files {
2
  
3
  export class FileTree {
4
​
5
    constructor(private _host: HTMLUListElement) {
6
    }
7
    
8
    
9
  }
10
​
11
  interface Entry {
12
    
13
    li: HTMLLIElement;
14
    name: string;
15
    fullPath: string;
16
​
17
    children: Entry[];
18
    
19
  }
20
​
21
  function loadEntry(parentPath: string, li: HTMLLIElement): Entry {
22
​
23
    var text = getLIText(li);
24
    var name: string, fullPath: string;
25
    if (text.charAt(0) === '/') {
26
      if (text.length < parentPath.length
27
        && text.slice(0, parentPath.length) === parentPath
28
        && text.charAt(parentPath.length) === '/') {
29
        fullPath = text;
30
        name = text.slice(parentPath.length + 1);
31
      }
32
      else {
33
        fullPath = parentPath + text;
34
        name = text.slice(1);
35
      }
36
    }
37
    else {
38
      fullPath = parentPath + '/' + text;
39
      name = text;
40
    }
41
​
42
    if (name.indexOf('/')) {
43
      // TODO: figure out something about invalid names with slashes
44
    }
45
​
46
    var ul = getChildUL(li);
47
    
48
    var children = getChildren(fullPath, ul);
49
    
50
    return {
51
      li: li,
52
      name: name,
53
      fullPath: fullPath,
54
      children: children
55
    };
56
    
57
  }
58
​
59
  function getLIText(li: HTMLLIElement): string { 
60
    
61
    for (var i = 0; i < li.childNodes.length; i++) {
62
      
63
      var node = li.childNodes.item(i);
64
      if ((<HTMLElement>node).tagName) continue;
65
      // TODO: check something for tag type
66
​
67
      return node.textContent;
68
    }
69
​
70
  }
71
​
72
  function getChildUL(li: HTMLLIElement): HTMLUListElement { 
73
    for (var i = 0; i < li.children.length; i++) {
74
      var ul = li.children.item(i);
75
      if (ul.tagName === 'UL' ||
76
        (ul.tagName && ul.tagName.toLowerCase() == 'ul'))
77
        return <HTMLUListElement>ul;
78
    }
79
    return null;
80
  }
81
​
82
  function getChildren(parentPath: string, ul: HTMLUListElement) {
83
    
84
  }
85
​
86
}
53:24